package com.yitiao.data_algorithms.leetcode.editor.cn;

class GreatestCommonDivisorOfStrings {
    // 2023-08-01 15:12:07
    public static void main(String[] args) {
        Solution solution = new GreatestCommonDivisorOfStrings().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String gcdOfStrings(String str1, String str2) {
            if (!str1.concat(str2).equals(str2.concat(str1))) {
                return "";
            }
            return str1.substring(0, gcd(str1.length(), str2.length()));
        }

        public int gcd(int a, int b) {
            int remainder = a % b;
            while (remainder != 0) {
                a = b;
                b = remainder;
                remainder = a % b;
            }
            return b;
        }
    }

//leetcode submit region end(Prohibit modification and deletion)

}